package com.niit.sqlite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by CWork on 2019-9-9.
 */

public class DBHelper extends SQLiteOpenHelper {
    //数据库名及版本号
    private static final String DB_NAME = "Students.db";
    private static final int    DB_VERSION = 1;
    //数据库表名及字段名
    public static final String TABLE_NAME = "Stu_info";
    public static final String STUDENT_ID = "_id";
    public static final String STUDENT_NAME = "_name";

    private static final String TABLE_CREATE =
            "create table if not exists "+TABLE_NAME
                    +"("+STUDENT_ID+" integer primary key autoincrement, "
                    +STUDENT_NAME+" text not null);";


    public DBHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(TABLE_CREATE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//        db.execSQL("drop table if exists"+TABLE_NAME);
//        onCreate(db);
    }
}
